package com.base_data_handler.surfer;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.HeadlessException;
import java.awt.Panel;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.Toolkit;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

public class ReadFile extends JFrame{

	/**
	 * 
	 */
	public static String latlng="108.002278, 34.618924;108.0064, 34.6226;108.020028, 34.622104;108.022644, 34.629135;108.033158, 34.625827;108.041586, 34.63177;108.036704, 34.63585;108.036776, 34.657155;108.029657, 34.673083;108.03322, 34.673743;108.034779, 34.679832;108.027882, 34.690344;108.023037, 34.719215;108.024504, 34.730834;108.015092, 34.74276;108.016165, 34.752456;108.007483, 34.776677;108.008847, 34.783606;107.985762, 34.799554;107.96762, 34.803911;107.95928, 34.813916;107.956509, 34.860403;107.961478, 34.871742;107.94837, 34.869079;107.937439, 34.855229;107.929823, 34.852746;107.891073, 34.848803;107.884553, 34.850438;107.87718, 34.859016;107.869143, 34.85147;107.859014, 34.853308;107.861775, 34.874087;107.852257, 34.893945;107.857175, 34.901941;107.846375, 34.910598;107.845371, 34.924499;107.827365, 34.946038;107.823611, 34.963579;107.828212, 34.9702;107.8268, 34.980148;107.812362, 34.979633;107.804676, 34.970616;107.794536, 34.975084;107.78707, 34.974723;107.730561, 34.957406;107.681925, 34.957083;107.674281, 34.953536;107.671102, 34.944371;107.664309, 34.943266;107.658006, 34.937836;107.648313, 34.942412;107.644066, 34.94104;107.644163, 34.92585;107.632084, 34.927142;107.639978, 34.946915;107.638409, 34.966668;107.618382, 34.974083;107.610216, 34.970572;107.607921, 34.96;107.602172, 34.958216;107.59449, 34.967712;107.578859, 34.971973;107.570504, 34.978087;107.570296, 34.969385;107.557238, 34.948822;107.543492, 34.93699;107.534527, 34.934872;107.536312, 34.92202;107.531932, 34.919029;107.501874, 34.917693;107.485544, 34.927334;107.470333, 34.918859;107.458126, 34.918507;107.447964, 34.928832;107.438194, 34.931918;107.428696, 34.930003;107.41174, 34.941357;107.406305, 34.938269;107.398656, 34.941216;107.387211, 34.938201;107.376612, 34.926033;107.374332, 34.917737;107.356063, 34.941616;107.30501, 34.944842;107.292514, 34.934561;107.285984, 34.921374;107.28795, 34.912676;107.257249, 34.903814;107.246542, 34.89715;107.233603, 34.897738;107.222523, 34.88911;107.213842, 34.893162;107.194765, 34.891313;107.189992, 34.903193;107.194367, 34.910119;107.194059, 34.918549;107.19071, 34.920719;107.189485, 34.930707;107.182157, 34.934706;107.177322, 34.943404;107.172932, 34.945446;107.159328, 34.941752;107.150211, 34.95443;107.14393, 34.951471;107.139627, 34.955111;107.134115, 34.951344;107.128472, 34.959439;107.11344, 34.958248;107.112852, 34.964607;107.10514, 34.975738;107.091569, 34.979212;107.090491, 34.984373;107.099263, 34.990053;107.102646, 34.997033;107.100365, 35.011187;107.094235, 35.022295;107.071033, 35.025041;107.061159, 35.029009;107.05896, 35.033741;107.054869, 35.032183;107.05745, 35.04702;107.051498, 35.044942;107.046679, 35.047365;107.037455, 35.035387;107.028609, 35.038767;107.016363, 35.035326;107.017422, 35.044065;107.005701, 35.062249;107.002778, 35.064839;106.989996, 35.0653;106.997434, 35.074211;106.995615, 35.075463;106.971405, 35.069919;106.961053, 35.071234;106.95398, 35.076358;106.950944, 35.086218;106.939084, 35.089113;106.937211, 35.081238;106.91904, 35.085859;106.916389, 35.09438;106.908186, 35.100705;106.894602, 35.094635;106.889718, 35.099223;106.866278, 35.097741;106.851224, 35.085703;106.835207, 35.085093;106.789529, 35.098864;106.770327, 35.098134;106.76482, 35.105562;106.755864, 35.102969;106.753626, 35.106221;106.7498, 35.104361;106.739659, 35.108371;106.728408, 35.098472;106.721065, 35.111511;106.717365, 35.106462;106.721316, 35.098892;106.713047, 35.092591;106.712997, 35.087944;106.674364, 35.083339;106.667913, 35.075836;106.657524, 35.082625;106.650646, 35.082456;106.646708, 35.077356;106.631879, 35.079266;106.629098, 35.0762;106.625601, 35.078426;106.622046, 35.076816;106.61165, 35.089188;106.602333, 35.088548;106.595018, 35.095645;106.589555, 35.093191;106.580319, 35.095013;106.577428, 35.085236;106.566783, 35.096223;106.550013, 35.091271;106.552161, 35.075362;106.536562, 35.052095;106.53344, 35.036827;106.529241, 35.034482;106.51607, 35.036213;106.505702, 35.042766;106.48676, 35.038751;106.499752, 35.022111;106.504985, 35.022199;106.499861, 35.005074;106.507282, 34.999466;106.489925, 34.988833;106.499108, 34.967764;106.500267, 34.9524;106.509722, 34.949093;106.511223, 34.931007;106.527841, 34.92634;106.519108, 34.9107;106.518693, 34.898891;106.539014, 34.884224;106.554057, 34.867671;106.572975, 34.833117;106.573289, 34.810527;106.54245, 34.792026;106.536916, 34.780227;106.555524, 34.762947;106.56062, 34.753274;106.536604, 34.754608;106.515246, 34.748996;106.506943, 34.753613;106.502737, 34.746659;106.505264, 34.73488;106.498604, 34.732908;106.49367, 34.72422;106.479826, 34.712908;106.47232, 34.715443;106.47148, 34.722001;106.463385, 34.719612;106.457349, 34.705658;106.461727, 34.689878;106.454644, 34.682495;106.457027, 34.67224;106.469153, 34.667519;106.477284, 34.659451;106.476425, 34.643048;106.465036, 34.645581;106.447889, 34.639617;106.447289, 34.6475;106.430381, 34.662055;106.424611, 34.647619;106.417267, 34.642228;106.410096, 34.642314;106.409774, 34.635825;106.396324, 34.628234;106.391903, 34.629947;106.388562, 34.637113;106.384115, 34.636211;106.374981, 34.622619;106.365905, 34.621495;106.358372, 34.611554;106.340974, 34.598754;106.320853, 34.594302;106.316923, 34.587234;106.317736, 34.584598;106.337135, 34.579422;106.350489, 34.566413;106.345899, 34.552156;106.349784, 34.539932;106.342153, 34.52504;106.355731, 34.524966;106.375658, 34.518886;106.38984, 34.526101;106.393228, 34.518452;106.40218, 34.515184;106.407856, 34.516469;106.409749, 34.525214;106.417377, 34.529759;106.428202, 34.529227;106.444263, 34.533512;106.454913, 34.530065;106.462164, 34.5374;106.46624, 34.535618;106.465946, 34.529156;106.474488, 34.536265;106.479721, 34.528941;106.485089, 34.527615;106.493577, 34.531958;106.49834, 34.521605;106.510783, 34.516386;106.520357, 34.517656;106.518437, 34.508872;106.52189, 34.503838;106.545945, 34.497114;106.548581, 34.485898;106.557954, 34.495481;106.56377, 34.495125;106.567352, 34.488642;106.579919, 34.489509;106.575411, 34.481175;106.590701, 34.479162;106.591448, 34.470887;106.608411, 34.470455;106.598152, 34.462187;106.606358, 34.458194;106.61751, 34.460084;106.619947, 34.453542;106.625664, 34.454042;106.623517, 34.444135;106.630659, 34.433838;106.631581, 34.419636;106.635431, 34.412167;106.646591, 34.407881;106.648467, 34.398873;106.659575, 34.39825;106.671273, 34.38851;106.685329, 34.390036;106.688031, 34.381679;106.697864, 34.385476;106.70425, 34.376995;106.708102, 34.376538;106.715221, 34.382622;106.721347, 34.376956;106.71959, 34.357449;106.70366, 34.354594;106.692701, 34.339325;106.707933, 34.330356;106.710051, 34.311328;106.704434, 34.295328;106.710898, 34.288353;106.704313, 34.280318;106.691207, 34.278668;106.685736, 34.260424;106.672947, 34.255593;106.651281, 34.253234;106.625598, 34.269786;106.620515, 34.266611;106.608603, 34.266632;106.596931, 34.256934;106.587816, 34.265374;106.588293, 34.271273;106.579791, 34.287583;106.558204, 34.287835;106.533566, 34.301215;106.530629, 34.294799;106.514332, 34.287523;106.516414, 34.280508;106.511102, 34.268399;106.493939, 34.254305;106.50827, 34.247084;106.518776, 34.250179;106.527558, 34.248299;106.531908, 34.261207;106.535114, 34.261952;106.546266, 34.254888;106.554108, 34.240791;106.562818, 34.232979;106.563434, 34.211433;106.571815, 34.201824;106.568476, 34.196211;106.577949, 34.180487;106.5839, 34.140467;106.566495, 34.117405;106.548565, 34.119914;106.538548, 34.115041;106.515693, 34.118113;106.507792, 34.116331;106.505767, 34.105107;106.514732, 34.087507;106.515198, 34.078009;106.501931, 34.062332;106.500749, 34.055634;106.493648, 34.051287;106.491087, 34.041997;106.484723, 34.04192;106.477906, 34.037477;106.477519, 34.024111;106.486722, 33.999537;106.480773, 33.993676;106.47872, 33.972813;106.470311, 33.96507;106.452986, 33.957635;106.45326, 33.944566;106.42954, 33.922214;106.417424, 33.915236;106.427104, 33.898085;106.421634, 33.889386;106.43167, 33.877372;106.449546, 33.875078;106.466546, 33.883539;106.468847, 33.890083;106.474989, 33.88229;106.48185, 33.881625;106.484415, 33.87154;106.499127, 33.861264;106.505669, 33.860299;106.505596, 33.85555;106.503535, 33.856551;106.492164, 33.839495;106.487917, 33.836725;106.474166, 33.837594;106.469945, 33.834609;106.468917, 33.819794;106.464698, 33.812646;106.467852, 33.793592;106.471611, 33.790808;106.485267, 33.792694;106.488011, 33.789421;106.489064, 33.756811;106.494541, 33.748106;106.487959, 33.736155;106.48622, 33.722214;106.48971, 33.717433;106.504167, 33.713741;106.508121, 33.709855;106.527352, 33.708031;106.546177, 33.685261;106.560238, 33.682014;106.557188, 33.666132;106.571074, 33.657393;106.573576, 33.646455;106.587329, 33.634685;106.58992, 33.592219;106.603312, 33.58531;106.615806, 33.596499;106.630445, 33.600381;106.630589, 33.619224;106.638011, 33.633061;106.644852, 33.640402;106.658417, 33.643009;106.660851, 33.647694;106.656559, 33.657389;106.649709, 33.661312;106.649477, 33.666457;106.660316, 33.669207;106.676671, 33.668007;106.711059, 33.681581;106.699946, 33.699894;106.684376, 33.705054;106.681475, 33.709781;106.69398, 33.709023;106.724992, 33.698064;106.758101, 33.694372;106.793669, 33.681301;106.807116, 33.683437;106.813291, 33.698987;106.808549, 33.707019;106.811254, 33.723154;106.805965, 33.731799;106.814024, 33.743409;106.818814, 33.771697;106.816585, 33.779047;106.808687, 33.782813;106.814963, 33.791362;106.810808, 33.801288;106.814105, 33.822326;106.824176, 33.837394;106.844411, 33.836781;106.858896, 33.853263;106.862208, 33.880038;106.865426, 33.883056;106.871321, 33.881463;106.879481, 33.871672;106.894577, 33.86605;106.899226, 33.861081;106.89739, 33.85333;106.906406, 33.850956;106.916667, 33.853775;106.934869, 33.839545;106.938526, 33.831281;106.956282, 33.827277;106.96065, 33.817937;106.969569, 33.816685;106.988068, 33.804366;107.000296, 33.804716;107.008118, 33.79895;107.02374, 33.80165;107.035249, 33.808467;107.050728, 33.804658;107.048381, 33.821945;107.051068, 33.82829;107.040488, 33.847045;107.048678, 33.854628;107.047036, 33.876266;107.056758, 33.883277;107.065947, 33.884668;107.070084, 33.8824;107.067724, 33.860275;107.070582, 33.84947;107.080085, 33.833429;107.091076, 33.826303;107.113345, 33.826719;107.118692, 33.818515;107.13652, 33.813859;107.141855, 33.804504;107.149198, 33.815885;107.155874, 33.819673;107.177452, 33.785307;107.206072, 33.778264;107.223423, 33.786435;107.245934, 33.777467;107.281008, 33.797578;107.284107, 33.788996;107.290559, 33.788995;107.316498, 33.777154;107.302981, 33.761612;107.301399, 33.7547;107.28565, 33.744134;107.285167, 33.735946;107.29258, 33.726891;107.294149, 33.713651;107.323657, 33.70841;107.330416, 33.699785;107.338127, 33.699383;107.356248, 33.691273;107.366161, 33.689056;107.37415, 33.694686;107.379132, 33.693915;107.392232, 33.68369;107.391824, 33.680136;107.404815, 33.665569;107.405159, 33.656006;107.414686, 33.651164;107.429377, 33.652458;107.438522, 33.656739;107.447176, 33.65572;107.454929, 33.664247;107.469291, 33.666369;107.481559, 33.676762;107.492361, 33.678817;107.498081, 33.693483;107.532509, 33.688829;107.544914, 33.693341;107.547881, 33.701698;107.55784, 33.704407;107.567819, 33.711932;107.593953, 33.705818;107.612834, 33.721333;107.633933, 33.726066;107.645834, 33.754096;107.670531, 33.76797;107.670412, 33.774727;107.6837, 33.78524;107.68537, 33.789785;107.679903, 33.805158;107.683684, 33.817453;107.695337, 33.831306;107.71154, 33.839414;107.711449, 33.847602;107.715247, 33.852532;107.712349, 33.861742;107.706462, 33.864887;107.691724, 33.865465;107.702255, 33.912907;107.7036, 33.938015;107.729578, 33.935185;107.77049, 33.956348;107.789956, 33.985745;107.795495, 33.989864;107.805776, 33.99152;107.815813, 34.000891;107.833873, 33.995821;107.837122, 33.990326;107.853157, 33.981111;107.864828, 33.983745;107.877069, 33.996226;107.903076, 34.008398;107.912681, 34.006969;107.922244, 33.992033;107.926445, 33.990343;107.948411, 33.988703;107.956539, 33.991115;107.948313, 34.01341;107.94987, 34.024388;107.9468, 34.032741;107.949683, 34.048016;107.961317, 34.051353;107.965407, 34.059069;107.976826, 34.064673;107.978292, 34.081524;107.991668, 34.090825;108.00521, 34.108764;108.003888, 34.120262;108.008828, 34.142225;108.005775, 34.154703;108.030984, 34.187097;108.029567, 34.196149;108.037272, 34.222044;108.034374, 34.235267;108.061489, 34.239341;108.063642, 34.254266;108.051743, 34.266247;108.062581, 34.273823;108.053567, 34.290486;108.031119, 34.290404;108.01155, 34.285723;108.005453, 34.288728;107.964603, 34.289227;107.952715, 34.294788;107.958879, 34.325677;107.962977, 34.329449;107.97882, 34.33026;107.9896, 34.321719;108.001326, 34.325959;108.000637, 34.337024;108.003691, 34.340528;108.015784, 34.32407;108.018334, 34.326906;108.028597, 34.327368;108.03539, 34.321711;108.059765, 34.329614;108.0572, 34.348783;108.041116, 34.356167;108.039649, 34.371801;108.035581, 34.378706;108.035439, 34.391801;108.047748, 34.394203;108.034478, 34.403309;108.039143, 34.406597;108.038114, 34.416148;108.01816, 34.446087;108.021536, 34.453491;108.018199, 34.471429;108.030025, 34.488913;108.024779, 34.493075;108.019925, 34.4891;108.008974, 34.491173;108.002005, 34.498099;108.003008, 34.505541;108.010581, 34.509252;108.008764, 34.520304;108.015342, 34.540664;107.998271, 34.573418;107.991206, 34.573178;107.986897, 34.580281;107.992134, 34.600331;108.001954, 34.611213;108.002278, 34.618924";
	public static List<Double> longitude;
	public static List<Double> latitude;
	
	public  int[] xPoints;
	public  int[] yPoints;
	public static String latlng2="107.743118, 34.323291;107.70484, 34.325385;107.697211, 34.322095;107.687887, 34.310345;107.673359, 34.311422;107.669176, 34.306555;107.665047, 34.289905;107.672753, 34.286351;107.674763, 34.280314;107.681086, 34.276443;107.681842, 34.255822;107.695834, 34.236883;107.684563, 34.219737;107.67741, 34.188061;107.655949, 34.16631;107.658989, 34.161995;107.679097, 34.155123;107.690189, 34.147532;107.713589, 34.126858;107.706239, 34.100736;107.707657, 34.090943;107.701981, 34.082655;107.710336, 34.061702;107.726796, 34.05007;107.733976, 34.038336;107.732524, 34.024808;107.745372, 34.009337;107.743258, 33.99712;107.751305, 33.993082;107.771122, 33.991716;107.789956, 33.985745;107.795495, 33.989864;107.805776, 33.99152;107.81174, 33.998723;107.818696, 34.000959;107.833873, 33.995821;107.84942, 33.98182;107.856907, 33.981325;107.864828, 33.983745;107.877069, 33.996226;107.903076, 34.008398;107.912681, 34.006969;107.922244, 33.992033;107.926445, 33.990343;107.954746, 33.990025;107.954907, 34.001811;107.948313, 34.01341;107.94987, 34.024388;107.9468, 34.032741;107.949683, 34.048016;107.961317, 34.051353;107.965407, 34.059069;107.976826, 34.064673;107.978292, 34.081524;107.991668, 34.090825;108.00521, 34.108764;108.003888, 34.120262;108.008828, 34.142225;108.005775, 34.154703;108.030984, 34.187097;108.029567, 34.196149;108.037272, 34.222044;108.034374, 34.235267;108.026629, 34.234094;108.011589, 34.23861;107.999719, 34.228931;107.980473, 34.232;107.967489, 34.225528;107.960516, 34.22781;107.953712, 34.22149;107.923243, 34.21975;107.90738, 34.221849;107.888642, 34.23762;107.859837, 34.239135;107.867031, 34.264683;107.860127, 34.268273;107.855363, 34.275873;107.855148, 34.295148;107.796952, 34.305822;107.755496, 34.324577;107.743118, 34.323291";
	public static List<Double> longitude2;
	public static List<Double> latitude2;
	private static final long serialVersionUID = 1L;
	
	static{
		longitude=new ArrayList<>();
		latitude=new ArrayList<>();
		longitude2=new ArrayList<>();
		latitude2=new ArrayList<>();
		String[] arr = latlng.split(";");
		for (int i = 0; i < arr.length; i++) {
			String[] ll = arr[i].split(",");
			longitude.add(Double.parseDouble(ll[1]));
			latitude.add(Double.parseDouble(ll[0]));
		}
		String[] arr2 = latlng2.split(";");
		for (int i = 0; i < arr2.length; i++) {
			String[] ll = arr2[i].split(",");
			longitude2.add(Double.parseDouble(ll[1]));
			latitude2.add(Double.parseDouble(ll[0]));
		}
		
	}
		
	        public ReadFile() throws HeadlessException {
	        	initialize();//调用初始化方法
	     }
			
	    //初始化方法
	    public void initialize(){
	        this.setSize(LocationTransfer.screenWidth, LocationTransfer.screenHeight);//设置窗体大小
	        //设置窗体的关闭方式
	        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
	        add(new CanvasPanel());//设置窗体面板为绘图面板对象
	        this.setTitle("绘制等值面");//设置窗体标题
	    }
	    
	    //创建内部类
	    @SuppressWarnings("serial")
		class CanvasPanel extends JPanel{
	        private Font font;
			public void paint(Graphics g){
	            super.paint(g);
	            Graphics2D g2=(Graphics2D)g;//强制类型转换位Graphics2D类型
	            //Graphics2D是推荐使用的绘图类，但是程序设计中提供的绘图对象大多是
	            //Graphics类的实例，这时应该使用强制类型转换将其转换为Graphics
	            g2.setBackground(Color.GREEN);
//	            g2.setClip(0, 0, 1000, 1000);裁剪
	            ArrayList<Point> data =new LocationTransfer().makeScreenPoint(longitude,latitude);
	            xPoints=new int[data.size()];
	            yPoints=new int[data.size()];
	            for (int i = 0; i < data.size(); i++) {
	            	xPoints[i]=(int) (data.get(i).getX());
	            	yPoints[i]=(int) data.get(i).getY()*4;
				}
	            g2.drawPolygon(xPoints,yPoints, data.size());
//	            g2.fillPolygon(xPoints,yPoints,data.size()*10);
	           
	            g2.setColor(Color.BLACK);
	            font=new Font("黑体",Font.ITALIC,18);
	            g2.setFont(font);
	            g2.drawString("江流儿", 150, 180);
	            g2.fillArc(150, 180, 10, 10, 0, 360);
	            g2.setColor(Color.BLUE);
	            g2.drawString("转过来试试", 180, 200);
	            g2.fillArc(180, 200, 10, 10, 0, 360);
	            
	            g2.rotate(135, 330, 350);
	            g2.setColor(Color.red);
	            
//	            ArrayList<Point> points = new LocationTransfer().makeScreenPoint(longitude2,latitude2);
//	           
//	            int[] xPoints2 = new int[points.size()];
//	            int[] yPoints2=new int[points.size()];
//	            for (int i = 0; i < points.size(); i++) {
//	            	xPoints2[i]=(int) (points.get(i).getX());
//	            	yPoints2[i]=(int) points.get(i).getY()*4;
//				}
//	        	g2.rotate(135, 330, 350);
//				g2.fillPolygon(xPoints2,yPoints2, points.size());
			
//	            g2.drawPolyline(xPoints,yPoints, data.size());
	          
	        }
	    }
	    public static void main(String[] args) {
	        // TODO Auto-generated method stub
	    	ReadFile df=new ReadFile();
	        df.setVisible(true);
	    }

}
